home *** CD-ROM | disk | FTP | other *** search
- // the implementation of class COMPONENT_LIST
- // Copyright (C) 1996, 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
-
- #include "../finfo.h"
- #include "../kbandef.h"
-
- #include "complist.h"
-
- XY COMPONENT_LIST::get_max() const
- {
- XY ac_max(X_MIN, Y_MIN);
- iterator i;
- TRAVERSE(*this, i) {
- ac_max = ::get_max(ac_max, i->get_max());
- }
- return ac_max;
- }
-
- XY COMPONENT_LIST::get_min() const
- {
- XY ac_min(X_MAX, Y_MAX);
- iterator i;
- TRAVERSE(*this, i) {
- ac_min = ::get_min(ac_min, i->get_min());
- }
- return ac_min;
- }
-
- void COMPONENT_LIST::shift(const XY& ac_dif, COMPONENT_LIST& target) const
- {
- iterator i;
- TRAVERSE(*this, i) {
- COMPONENT_ELEMENT shifted;
- i->shift(ac_dif, shifted);
- target.push_back(shifted);
- }
- }
-
- void COMPONENT_LIST::unselect()
- {
- iterator i;
- TRAVERSE(*this, i) {
- i->unselect();
- }
- }
-
- void COMPONENT_LIST::select_items_in_block(const XY& ac1, const XY& ac2)
- {
- iterator i;
- TRAVERSE(*this, i) {
- if(i->is_in_block(ac1, ac2)) {
- i->select();
- }
- }
- }
-
- void COMPONENT_LIST::collect_selected_items(COMPONENT_LIST& dst) const
- {
- iterator i;
- TRAVERSE(*this, i) {
- if(i->is_selected()) {
- dst.push_back(*i);
- }
- }
- }
-
- void COMPONENT_LIST::remove_selected_items()
- {
- iterator i;
- TRAVERSE(*this, i) {
- if(i->is_selected()) {
- iterator current_i = i--;
- erase(current_i);
- }
- }
- }
-
- int COMPONENT_LIST::load_170(FILE_NEW& fp)
- {
- char str[1024];
- fp.gets_wo_return(str, 1024);
- for(;;) {
- long pos = fp.tell();
- fp.gets_wo_return(str, 1024);
- if(!strcmp(str, "end")) {
- break;
- }
- COMPONENT_ELEMENT element;
- fp.seek(pos, SEEK_SET);
- element.load_170(fp);
- push_back(element);
- }
- return true;
- }
-
- void COMPONENT_LIST::load_200b18(FILE_NEW& fp)
- {
- for(;;) {
- char str[1024];
- long pos = fp.tell();
- fp.gets_wo_return(str, 1024);
- if(!strcmp(str, "end")) {
- break;
- }
- COMPONENT_ELEMENT element;
- fp.seek(pos, SEEK_SET);
- element.load(fp);
- push_back(element);
- }
- }
-
- uint COMPONENT_LIST::load_get_version(FILE_NEW& fp) const
- {
- FILE_VERSION fver;
- char str[1024];
- fp.gets_wo_return(str, 1024);
- return fver.get_version_no(str);
- }
-
- COMPONENT_LIST::LOAD_FUNC_INFO COMPONENT_LIST::load_func_table[] = {
- {FILE_VERSION::VERSION_200B18 , &COMPONENT_LIST::load_200b18},
- {FILE_VERSION::VERSION_UNKNOWN, NULL }
- };
-
- COMPONENT_LIST::LOAD_FUNC COMPONENT_LIST::get_load_func(uint version) const
- {
- uint sentinel = FILE_VERSION::VERSION_UNKNOWN;
- uint index = search_info_table(load_func_table, sentinel, version);
- return load_func_table[index].func;
- }
-
- int COMPONENT_LIST::load(FILE_NEW& fp)
- {
- int retval;
- uint version = load_get_version(fp);
- LOAD_FUNC load_func = get_load_func(version);
- if(load_func != NULL) {
- (this->*load_func)(fp);
- retval = true;
- } else {
- retval = false;
- }
- return retval;
- }
-
- int COMPONENT_LIST::save(FILE_NEW& fp) const
- {
- FILE_VERSION fver;
- fp.printf("%s\n", fver.get_version_str(FILE_VERSION::VERSION_200B18));
-
- iterator i;
- TRAVERSE(*this, i) {
- i->save(fp);
- }
-
- fp.puts("end\n");
- return true;
- }
-
- void COMPONENT_LIST::collect_aperture(APT_TABLE& apt_pin_table, APT_TABLE& apt_line_table) const
- {
- iterator i;
- TRAVERSE(*this, i) {
- i->collect_aperture(apt_pin_table, apt_line_table);
- }
- }
-
- void COMPONENT_LIST::operator+=(const COMPONENT_LIST& target)
- {
- insert(end(), target.begin(), target.end());
- }
-
- COMPONENT_ELEMENT* COMPONENT_LIST::search(const XY& ac)
- {
- COMPONENT_ELEMENT* p = NULL;
- iterator i;
- TRAVERSE(*this, i) {
- if(ac.is_in_box(i->get_min(), i->get_max())) {
- p = &*i;
- break;
- }
- }
- return p;
- }
-
- COMPONENT_ELEMENT* COMPONENT_LIST::search_designator(const char* designator)
- {
- COMPONENT_ELEMENT* p = NULL;
- iterator i;
- TRAVERSE(*this, i) {
- if(!strcmp(i->designator(), designator)) {
- p = &*i;
- break;
- }
- }
- return p;
- }
-
- void COMPONENT_LIST::rotate_90()
- {
- iterator i;
- TRAVERSE(*this, i) {
- i->rotate_90();
- }
- }
-
- void COMPONENT_LIST::limit_drill_size(uint drill)
- {
- iterator i;
- TRAVERSE(*this, i) {
- i->limit_drill_size(drill);
- }
- }
-